package com.ixuestar.service.impl;

import java.text.DecimalFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ixuestar.dao.IxuestarTeacherMapper;
import com.ixuestar.entity.ExaminationInfo;
import com.ixuestar.entity.ExaminationQuestions;
import com.ixuestar.entity.ExaminationResults;
import com.ixuestar.entity.Examinationclass;
import com.ixuestar.entity.Examinationsubject;
import com.ixuestar.entity.MultipleChoiceQuestion;
import com.ixuestar.entity.QuestionScore;
import com.ixuestar.entity.SchoolClass;
import com.ixuestar.entity.SchoolStudent;
import com.ixuestar.entity.SchoolTeacher;
import com.ixuestar.entity.Schoolposition;
import com.ixuestar.entity.Schoolposttea;
import com.ixuestar.entity.SingleChoiceQuestion;
import com.ixuestar.entity.Subject;
import com.ixuestar.entity.SubjectiveQuestions;
import com.ixuestar.entity.SubjectiveQuestionsInterval;
import com.ixuestar.service.IxuestarTeacherService;

@Service("/smallAppTeacherService")
@Transactional
public class IxuestarTeacherServiceImpl implements IxuestarTeacherService {
	
	//创建logger
	private Logger logger = Logger.getLogger(IxuestarTeacherServiceImpl.class);
	
	@Autowired
	private IxuestarTeacherMapper smallAppTeacherMapper;

	@Override
	public JSONObject getSchoolTeacher(String ixstTelephone) {
		// TODO Auto-generated method stub
		JSONObject jsObject = new JSONObject();
		try {
			Map<String, Object> hashMap = new HashMap<>();
			hashMap.put("lineKey", "ixstTelephone");
			hashMap.put("lineValue", ixstTelephone);
			SchoolTeacher schoolTeacherInfo = smallAppTeacherMapper.getSchoolTeacherInfo(hashMap);
			if (schoolTeacherInfo!=null) {
				String ixstId = schoolTeacherInfo.getIxstId();
				String ixstName = schoolTeacherInfo.getIxstName();
				jsObject.put("code", 0);
				jsObject.put("ixstId", ixstId);
				jsObject.put("ixstName", ixstName);
				jsObject.put("ixstTelephone", ixstTelephone);
				logger.info("-------------老师基本信息-"+jsObject+"--------------");
			}else {
				jsObject.put("code", 1);
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return jsObject;
	}
	
	@Override
	public JSONObject getExaminationinfo(String ixstId) {
		// TODO Auto-generated method stub
		JSONObject jsonObject = new JSONObject();
		try {
			Map<String, Object> hashMap = new HashMap<>();
			hashMap.put("lineKey", "ixstId");
			hashMap.put("lineValue", ixstId);
			SchoolTeacher schoolTeacherInfo = smallAppTeacherMapper.getSchoolTeacherInfo(hashMap);
			if (schoolTeacherInfo!=null) {
				String ixsgId = schoolTeacherInfo.getIxsgId();
				//获取考试列表
				JSONArray jsonArray = new JSONArray();
				List<ExaminationInfo> examinationInfos = smallAppTeacherMapper.getExaminationInfos(ixsgId);
				for (int i = 0; i < examinationInfos.size(); i++) {
					ExaminationInfo examinationInfo = examinationInfos.get(i);
					jsonArray.add(examinationInfo);
				}
				int jsonArraySize = jsonArray.size();
				jsonObject.put("examinationInfo", jsonArray);
				jsonObject.put("examinationInfoSize", jsonArraySize);
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return jsonObject;
	}
	
	@Override
	public JSONObject getSchoolTeacherInfo(String ixstId,String ixeId) {
		// TODO Auto-generated method stub
		JSONObject jsObject = new JSONObject();
		try {
			//1、通过手机号获取老师的姓名等相关信息
			Map<String, Object> hashMap = new HashMap<>();
			hashMap.put("lineKey", "ixstId");
			hashMap.put("lineValue", ixstId);
			SchoolTeacher schoolTeacherInfo = smallAppTeacherMapper.getSchoolTeacherInfo(hashMap);
			//判断一下老师的手机号是否存在
			if (schoolTeacherInfo!=null) {
//				String ixst = schoolTeacherInfo.getIxstTelephone();
				String ixstName = schoolTeacherInfo.getIxstName();
				//2、通过教师信息id获取老师的权限集合
				List<String> list = new LinkedList<>();
				hashMap.put("lineKey", "ixstId");
				hashMap.put("lineValue", ixstId);
				List<Schoolposttea> schoolposttea = smallAppTeacherMapper.getSchoolposttea(hashMap);
				for (int i = 0; i < schoolposttea.size(); i++) {
					String ixspId = schoolposttea.get(i).getIxspId();
					if (!list.contains(ixspId)) {
						list.add(ixspId);
					}
				}
				Collections.sort(list);
				//3、根据相应的权限，获取要展示的科目和班级
				JSONArray jsonArray = new JSONArray();
				for (int i = 0; i < list.size(); i++) {
					//获取权限id
					String ixspId = list.get(i);
					//获取权限信息
					Schoolposition schoolpositionInfo = smallAppTeacherMapper.getSchoolpositionInfo(ixspId);
					String ixspName = schoolpositionInfo.getIxspName();
					int ixspType = Integer.parseInt(schoolpositionInfo.getIxspType());
					//判断不同类型的角色获取不同的信息
					//首先是学科老师
					if (ixspType==0) {
						//学科老师的科目已定 直接获取老师所教的班级就好
						JSONObject jsObject0 = new JSONObject();
						//获取老师所教的科目
						String ixsId = schoolTeacherInfo.getIxsId();
						//判断此次考试是否考试此科目
						hashMap.put("ixsId", ixsId);
						hashMap.put("ixeId", ixeId);
						Examinationsubject examinationsubject = smallAppTeacherMapper.getExaminationsubject(hashMap);
						if (examinationsubject!=null) {
							//获取科目信息
							Subject subjectInfo = smallAppTeacherMapper.getSubjectInfo(ixsId);
							String ixsName = subjectInfo.getIxsName();
							String ixesId = examinationsubject.getIxesId();
							JSONObject jsonObject1 = new JSONObject();
							jsonObject1.put("ixsId", ixsId);
							jsonObject1.put("ixesId", ixesId);
							jsonObject1.put("ixsName", ixsName);
							JSONArray jsonArray1 = new JSONArray();
							jsonArray1.add(jsonObject1);
							jsObject0.put("examinationSubject", jsonArray1);
							//获取所教的班级
							hashMap.put("ixstId", ixstId);
							hashMap.put("ixspId", ixspId);
							List<Schoolposttea> schoolposttea2 = smallAppTeacherMapper.getSchoolpostteas(hashMap);
							JSONArray jsonArray2 = new JSONArray();
							for (int j = 0; j < schoolposttea2.size(); j++) {
								JSONObject jsonObject2 = new JSONObject();
								//获取对象
								Schoolposttea schoolposttea3 = schoolposttea2.get(j);
								String ixscId = schoolposttea3.getIxscId();
								//获取班级编号
								hashMap.put("lineKey", "ixscId");
								hashMap.put("lineValue", ixscId);
								SchoolClass schoolClassInfos = smallAppTeacherMapper.getSchoolClassInfos(hashMap);
								String ixscNo = schoolClassInfos.getIxscNo();
								jsonObject2.put("ixscId", ixscId);
								jsonObject2.put("ixscNo", ixscNo);
								jsonArray2.add(jsonObject2);
							}
							jsObject0.put("examinationClass", jsonArray2);
						}
						jsObject0.put("ixspId", ixspId);
						jsObject0.put("ixspName", ixspName);
						jsonArray.add(jsObject0);
					}else if(ixspType==1){
						//类型为1：代表是班主任 班主任来说就是班级定了 展示所有科目
						JSONObject jsObject1 = new JSONObject();
						//获取此次考试的所有可是科目
						JSONArray jsonArray1 = new JSONArray();
						hashMap.put("lineKey", "ixeId");
						hashMap.put("lineValue", ixeId);
						List<Examinationsubject> examinationsubjects = smallAppTeacherMapper.getExaminationsubjects(hashMap);
						for (int j = 0; j < examinationsubjects.size(); j++) {
							JSONObject jsonObject1 = new JSONObject();
							//获取考试科目对象
							Examinationsubject examinationsubject = examinationsubjects.get(j);
							String ixsId = examinationsubject.getIxsId();
							String ixesId = examinationsubject.getIxesId();
							//获取科目信息
							Subject subjectInfo = smallAppTeacherMapper.getSubjectInfo(ixsId);
							String ixsName = subjectInfo.getIxsName();
							jsonObject1.put("ixsId", ixsId);
							jsonObject1.put("ixesId", ixesId);
							jsonObject1.put("ixsName", ixsName);
							jsonArray1.add(jsonObject1);
						}
						//获取所教的班级
						JSONArray jsonArray2 = new JSONArray();
						hashMap.put("ixstId", ixstId);
						hashMap.put("ixspId", ixspId);
						List<Schoolposttea> schoolpostteas = smallAppTeacherMapper.getSchoolpostteas(hashMap);
						for (int k = 0; k < schoolpostteas.size(); k++) {
							JSONObject jsonObject2 = new JSONObject();
							//获取权限关系对象
							Schoolposttea schoolposttea2 = schoolpostteas.get(k);
							//获取班级列表
							String ixscId = schoolposttea2.getIxscId();
							//获取班级编号
							hashMap.put("lineKey", "ixscId");
							hashMap.put("lineValue", ixscId);
							SchoolClass schoolClassInfos = smallAppTeacherMapper.getSchoolClassInfos(hashMap);
							String ixscNo = schoolClassInfos.getIxscNo();
							jsonObject2.put("ixscId", ixscId);
							jsonObject2.put("ixscNo", ixscNo);
							jsonArray2.add(jsonObject2);
						}
						jsObject1.put("ixspId", ixspId);
						jsObject1.put("ixspName", ixspName);
						jsObject1.put("examinationSubject", jsonArray1);
						jsObject1.put("examinationClass", jsonArray2);
						jsonArray.add(jsObject1);
					}else if (ixspType==2) {
						//类型为1：代表是学科主任 学科主任来说就是学科班级定了 展示所有班级
						JSONObject jsObject2 = new JSONObject();
						//获取老师所教的科目
						String ixsId = schoolTeacherInfo.getIxsId();
						//判断此次考试是否考试此科目
						hashMap.put("ixsId", ixsId);
						hashMap.put("ixeId", ixeId);
						Examinationsubject examinationsubject = smallAppTeacherMapper.getExaminationsubject(hashMap);
						if (examinationsubject!=null) {
							//获取科目信息
							Subject subjectInfo = smallAppTeacherMapper.getSubjectInfo(ixsId);
							String ixsName = subjectInfo.getIxsName();
							String ixesId = examinationsubject.getIxesId();
							JSONObject jsonObject1 = new JSONObject();
							jsonObject1.put("ixsId", ixsId);
							jsonObject1.put("ixesId", ixesId);
							jsonObject1.put("ixsName", ixsName);
							JSONArray jsonArray1 = new JSONArray();
							jsonArray1.add(jsonObject1);
							//获取所教的班级
							JSONArray jsonArray2 = new JSONArray();
							hashMap.put("lineKey", "ixeId");
							hashMap.put("lineValue", ixeId);
							List<Examinationclass> examinationclasses = smallAppTeacherMapper.getExaminationclasses(hashMap);
							for (int j = 0; j < examinationclasses.size(); j++) {
								//创建盛放容器
								JSONObject jsonObject2 = new JSONObject();
								//获取考试情况对象
								Examinationclass examinationclass = examinationclasses.get(j);
								String ixscId = examinationclass.getIxscId();
								//获取班级编号
								hashMap.put("lineKey", "ixscId");
								hashMap.put("lineValue", ixscId);
								SchoolClass schoolClassInfos = smallAppTeacherMapper.getSchoolClassInfos(hashMap);
								String ixscNo = schoolClassInfos.getIxscNo();
								jsonObject2.put("ixscId", ixscId);
								jsonObject2.put("ixscNo", ixscNo);
								jsonArray2.add(jsonObject2);
							}
							jsObject2.put("ixspId", ixspId);
							jsObject2.put("ixspName", ixspName);
							jsObject2.put("examinationSubject", jsonArray1);
							jsObject2.put("examinationClass", jsonArray2);
							jsonArray.add(jsObject2);
						}
					}else if (ixspType==3) {
						//类型为3：代表是年级主任 年级主任就是要获取所有的考试科目和考试班级
						JSONObject jsObject3 = new JSONObject();
						//获取此次考试的所有可是科目
						JSONArray jsonArray1 = new JSONArray();
						hashMap.put("lineKey", "ixeId");
						hashMap.put("lineValue", ixeId);
						List<Examinationsubject> examinationsubjects = smallAppTeacherMapper.getExaminationsubjects(hashMap);
						for (int j = 0; j < examinationsubjects.size(); j++) {
							JSONObject jsonObject1 = new JSONObject();
							//获取考试科目对象
							Examinationsubject examinationsubject = examinationsubjects.get(j);
							String ixsId = examinationsubject.getIxsId();
							String ixesId = examinationsubject.getIxesId();
							//获取科目信息
							Subject subjectInfo = smallAppTeacherMapper.getSubjectInfo(ixsId);
							String ixsName = subjectInfo.getIxsName();
							jsonObject1.put("ixsId", ixsId);
							jsonObject1.put("ixesId", ixesId);
							jsonObject1.put("ixsName", ixsName);
							jsonArray1.add(jsonObject1);
						}
						//获取所教的班级
						JSONArray jsonArray2 = new JSONArray();
						hashMap.put("lineKey", "ixeId");
						hashMap.put("lineValue", ixeId);
						List<Examinationclass> examinationclasses = smallAppTeacherMapper.getExaminationclasses(hashMap);
						for (int j = 0; j < examinationclasses.size(); j++) {
							//创建盛放容器
							JSONObject jsonObject2 = new JSONObject();
							//获取考试情况对象
							Examinationclass examinationclass = examinationclasses.get(j);
							String ixscId = examinationclass.getIxscId();
							//获取班级编号
							hashMap.put("lineKey", "ixscId");
							hashMap.put("lineValue", ixscId);
							SchoolClass schoolClassInfos = smallAppTeacherMapper.getSchoolClassInfos(hashMap);
							String ixscNo = schoolClassInfos.getIxscNo();
							jsonObject2.put("ixscId", ixscId);
							jsonObject2.put("ixscNo", ixscNo);
							jsonArray2.add(jsonObject2);
						}
						jsObject3.put("ixspId", ixspId);
						jsObject3.put("ixspName", ixspName);
						jsObject3.put("examinationSubject", jsonArray1);
						jsObject3.put("examinationClass", jsonArray2);
						jsonArray.add(jsObject3);
					}
				}
				jsObject.put("code", 0);
				jsObject.put("ixstId", ixstId);
				jsObject.put("ixstName", ixstName);
				jsObject.put("jurisdiction", jsonArray);
			}else {
				jsObject.put("code", 1);
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return jsObject;
	}
	
	@Override
	public JSONObject getTestScoresInfo(String ixesId, String ixscId) {
		// TODO Auto-generated method stub
		JSONObject jsonObject = new JSONObject();
		try {
			JSONArray jsonArray = new JSONArray();
			//获取考试城市列表
			Map<String, Object> hashMap = new HashMap<>();
			hashMap.put("ixscId", ixscId);
			hashMap.put("ixesId", ixesId);
			List<ExaminationResults> examinationResults = smallAppTeacherMapper.getExaminationResults(hashMap);
			double total = 0.00;
			for (int i = 0; i < examinationResults.size(); i++) {
				ExaminationResults examinationResult = examinationResults.get(i);
				//获取学生id
				String ixssId = examinationResult.getIxssId();
				String ixerScore = examinationResult.getIxerRawScore();
				total = total + Double.parseDouble(ixerScore);
				//获取学生姓名
				hashMap.put("lineKey", "ixssId");
				hashMap.put("lineValue", ixssId);
				logger.info("------------"+hashMap+"------------");
				SchoolStudent schoolStudentInfo = smallAppTeacherMapper.getSchoolStudentInfo(hashMap);
				//获取学生姓名
				String ixssName = schoolStudentInfo.getIxssName().replaceAll("\\s*", "");
				String jsonString = JSON.toJSONString(examinationResult);
				JSONObject parseObject = JSON.parseObject(jsonString);
				parseObject.put("ixssName", ixssName);
				jsonArray.add(parseObject);
			}
			logger.info("----总分:--"+total+"------");
			//查询个数
			int studentSize = jsonArray.size();
			double averageScore = total / studentSize;
			//添加对象
			jsonObject.put("studentScore", jsonArray);
			jsonObject.put("studentSize", studentSize);
			jsonObject.put("averageScore", averageScore);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return jsonObject;
	}
	
	@Override
	public JSONObject getExaminationResultSection(String ixesId, String ixscId) {
		// TODO Auto-generated method stub
		JSONObject jsonObject = new JSONObject();
		try {
			//获取参加科目的信息
			Map<String, Object> hashMap = new HashMap<>();
			hashMap.put("lineKey", "ixesId");
			hashMap.put("lineValue", ixesId);
			List<Examinationsubject> examinationsubjects = smallAppTeacherMapper.getExaminationsubjects(hashMap);
			//判断是否存在此科目
			if (examinationsubjects.size()!=0) {
				//获取科目信息
				Examinationsubject examinationsubject = examinationsubjects.get(0);
				String ixsId = examinationsubject.getIxsId();
				String ixsFullMarks = smallAppTeacherMapper.getSubjectInfo(ixsId).getIxsFullMarks();
				int interval = Integer.parseInt(ixsFullMarks)/10;

				int downScore = 0;
				String intervalString = "";
				//循环获取区间的人数
				hashMap.put("ixscId", ixscId);
				hashMap.put("ixesId", ixesId);
				JSONArray jsonArray = new JSONArray();
				for (int i = 0; i < interval; i++) {
					//创建区间
					JSONObject jsonObject1 = new JSONObject();
					int upScore = downScore + 10;
					if (i==interval-1) {
						hashMap.put("flag", 1);
						intervalString = "["+downScore+","+upScore+"]";
					}else {
						hashMap.put("flag", 0);
						intervalString = "["+downScore+","+upScore+")";
					}
					hashMap.put("upScore", upScore);
					hashMap.put("downScore", downScore);
					//下限叠加
					downScore += 10;
					//获取人数
					List<ExaminationResults> examinationResultSection = smallAppTeacherMapper.getExaminationResultSection(hashMap);
					jsonObject1.put("interval", intervalString);
					jsonObject1.put("intervalNum", examinationResultSection.size());
					jsonArray.add(jsonObject1);
				}
				//获取区间个数
				jsonObject.put("interv", jsonArray);
				jsonObject.put("intervNum", jsonArray.size());
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return jsonObject;
	}
	
	@Override
	public JSONObject getSingleChoiceQuestion(String ixesId, String ixscId) {
		// TODO Auto-generated method stub
		JSONObject jsonObject = new JSONObject();
		try {
			//创建参数容器
			Map<String, Object> hashMap = new HashMap<>();
			hashMap.put("ixesId", ixesId);
			hashMap.put("ixeqType", "O");
			List<ExaminationQuestions> examinationQuestionsInfo = smallAppTeacherMapper.getExaminationQuestionsInfo(hashMap);
			//循环获取题目信息
			JSONArray jsonArray = new JSONArray();
			for (int i = 0; i < examinationQuestionsInfo.size(); i++) {
				JSONObject jsonObject1 = new JSONObject();
				//获取题目对象
				ExaminationQuestions examinationQuestions = examinationQuestionsInfo.get(i);
				//获取题目信息
				String ixeqId = examinationQuestions.getIxeqId();
				String ixeqNo = examinationQuestions.getIxeqNo();
				String ixeqRightkey = examinationQuestions.getIxeqRightkey();
				String ixeqFullmarks = examinationQuestions.getIxeqFullmarks();
				//获取单个选择题目选项个数
				hashMap.put("ixscId", ixscId);
				hashMap.put("ixeqId", ixeqId);
				SingleChoiceQuestion singleChoiceQuestionInfo = smallAppTeacherMapper.getSingleChoiceQuestionInfo(hashMap);
				//获取选项的人数
				double ixeqOptionA = Double.parseDouble(singleChoiceQuestionInfo.getIxeqOptionA());
				double ixeqOptionB = Double.parseDouble(singleChoiceQuestionInfo.getIxeqOptionB());
				double ixeqOptionC = Double.parseDouble(singleChoiceQuestionInfo.getIxeqOptionC());
				double ixeqOptionD = Double.parseDouble(singleChoiceQuestionInfo.getIxeqOptionD());
				//获取考试总人数
				double total = ixeqOptionA + ixeqOptionB + ixeqOptionC + ixeqOptionD;				
				//获取正确
				String rightKeyRate = "";
				if (ixeqRightkey.contains("A")) {
					rightKeyRate = new DecimalFormat("0.00").format(ixeqOptionA/total);
				}else if (ixeqRightkey.contains("B")) {
					rightKeyRate = new DecimalFormat("0.00").format(ixeqOptionB/total);
				}else if (ixeqRightkey.contains("C")) {
					rightKeyRate = new DecimalFormat("0.00").format(ixeqOptionC/total);
				}else if (ixeqRightkey.contains("D")) {
					rightKeyRate = new DecimalFormat("0.00").format(ixeqOptionD/total);
				}
				jsonObject1.put("ixeqId", ixeqId);
				jsonObject1.put("ixeqNo", ixeqNo);
				jsonObject1.put("ixeqOptionA", ixeqOptionA);
				jsonObject1.put("ixeqOptionB", ixeqOptionB);
				jsonObject1.put("ixeqOptionC", ixeqOptionC);
				jsonObject1.put("ixeqOptionD", ixeqOptionD);
				jsonObject1.put("ixeqRightkey", ixeqRightkey);
				jsonObject1.put("rightKeyRate", rightKeyRate);
				jsonObject1.put("ixeqFullmarks", ixeqFullmarks);
				jsonArray.add(jsonObject1);
			}
			//获取选择题的个数
			int size = jsonArray.size();
			jsonObject.put("singleChoiceQuestion", jsonArray);
			jsonObject.put("singleChoiceQuestionSize", size);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return jsonObject;
	}
	
	@Override
	public JSONObject getMultipleChoiceQuestion(String ixesId, String ixscId) {
		// TODO Auto-generated method stub
		JSONObject jsonObject = new JSONObject();
		try {
			//创建参数容器
			Map<String, Object> hashMap = new HashMap<>();
			hashMap.put("ixesId", ixesId);
			hashMap.put("ixeqType", "M");
			List<ExaminationQuestions> examinationQuestionsInfo = smallAppTeacherMapper.getExaminationQuestionsInfo(hashMap);
			//循环获取题目信息
			JSONArray jsonArray = new JSONArray();
			for (int i = 0; i < examinationQuestionsInfo.size(); i++) {
				JSONObject jsonObject1 = new JSONObject();
				//获取题目对象
				ExaminationQuestions examinationQuestions = examinationQuestionsInfo.get(i);
				//获取题目信息
				String ixeqId = examinationQuestions.getIxeqId();
				String ixeqNo = examinationQuestions.getIxeqNo();
				String ixeqRightkey = examinationQuestions.getIxeqRightkey();
				String ixeqFullmarks = examinationQuestions.getIxeqFullmarks();
				//获取单个选择题目选项个数
				hashMap.put("ixscId", ixscId);
				hashMap.put("ixeqId", ixeqId);
				MultipleChoiceQuestion multipleChoiceQuestionInfo = smallAppTeacherMapper.getMultipleChoiceQuestionInfo(hashMap);
				double ixeqZeroScoRate = Double.parseDouble(multipleChoiceQuestionInfo.getIxeqZeroScoRate());
				double ixeqOtherScores = Double.parseDouble(multipleChoiceQuestionInfo.getIxeqOtherScores());
				double ixeqFullMarkRate = Double.parseDouble(multipleChoiceQuestionInfo.getIxeqFullMarkRate());
				//总人数
				double total = ixeqZeroScoRate + ixeqOtherScores + ixeqFullMarkRate;
				String rightKeyRate = new DecimalFormat("0.00").format(ixeqFullMarkRate/total);
				//添加
				jsonObject1.put("ixeqId", ixeqId);
				jsonObject1.put("ixeqNo", ixeqNo);
				jsonObject1.put("ixeqZeroScoRate", ixeqZeroScoRate);
				jsonObject1.put("ixeqOtherScores", ixeqOtherScores);
				jsonObject1.put("ixeqFullMarkRate", ixeqFullMarkRate);
				jsonObject1.put("ixeqRightkey", ixeqRightkey);
				jsonObject1.put("rightKeyRate", rightKeyRate);
				jsonObject1.put("ixeqFullmarks", ixeqFullmarks);
				jsonArray.add(jsonObject1);
			}
			//获取选择题的个数
			int size = jsonArray.size();
			jsonObject.put("multipleChoiceQuestion", jsonArray);
			jsonObject.put("multipleChoiceQuestionSize", size);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return jsonObject;
	}
	
	@Override
	public JSONObject getSubjectivequestions(String ixesId, String ixscId) {
		// TODO Auto-generated method stub
		JSONObject jsonObject = new JSONObject();
		try {
			//创建参数容器
			Map<String, Object> hashMap = new HashMap<>();
			hashMap.put("ixesId", ixesId);
			hashMap.put("ixeqType", "S");
			List<ExaminationQuestions> examinationQuestionsInfo = smallAppTeacherMapper.getExaminationQuestionsInfo(hashMap);
			//循环获取题目信息
			JSONArray jsonArray = new JSONArray();
			for (int i = 0; i < examinationQuestionsInfo.size(); i++) {
				JSONObject jsonObject1 = new JSONObject();
				//获取题目对象
				ExaminationQuestions examinationQuestions = examinationQuestionsInfo.get(i);
				//获取题目信息
				String ixeqId = examinationQuestions.getIxeqId();
				String ixeqNo = examinationQuestions.getIxeqNo();
				String ixeqRightkey = examinationQuestions.getIxeqRightkey();
				String ixeqFullmarks = examinationQuestions.getIxeqFullmarks();
				hashMap.put("ixscId", ixscId);
				hashMap.put("ixeqId", ixeqId);
				SubjectiveQuestions subjectiveQuestionsInfo = smallAppTeacherMapper.getSubjectiveQuestionsInfo(hashMap);
				double ixsqAverage = subjectiveQuestionsInfo.getIxsqAverage();
				int ixsqTotalScore = subjectiveQuestionsInfo.getIxsqTotalScore();
				double ixsqScoringRate = subjectiveQuestionsInfo.getIxsqScoringRate();
				//获取分段情况
				List<SubjectiveQuestionsInterval> subjectiveQuestionsIntervals = smallAppTeacherMapper.getSubjectiveQuestionsIntervals(hashMap);
				//添加
				jsonObject1.put("ixeqId", ixeqId);
				jsonObject1.put("ixeqNo", ixeqNo);
				jsonObject1.put("ixsqAverage", ixsqAverage);
				jsonObject1.put("ixeqRightkey", ixeqRightkey);
				jsonObject1.put("ixeqFullmarks", ixeqFullmarks);
				jsonObject1.put("ixsqTotalScore", ixsqTotalScore);
				jsonObject1.put("ixsqScoringRate", ixsqScoringRate);
				jsonObject1.put("questionsIntervals", subjectiveQuestionsIntervals);
				jsonArray.add(jsonObject1);
			}
			//获取选择题的个数
			int size = jsonArray.size();
			jsonObject.put("subjectiveQuestion", jsonArray);
			jsonObject.put("subjectiveQuestionSize", size);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return jsonObject;
	}
	
	@Override
	public JSONObject getQuestionScore(String ixesId, String ixscId,String ixeqId) {
		// TODO Auto-generated method stub
		JSONObject jsonObject = new JSONObject();
		try {
			//首先获取题目的类型
			Map<String, Object> hashMap = new HashMap<>();
			hashMap.put("lineKey", "ixeqId");
			hashMap.put("lineValue", ixeqId);
			List<ExaminationQuestions> examinationQuestion = smallAppTeacherMapper.getExaminationQuestion(hashMap);
			for (int i = 0; i < examinationQuestion.size(); i++) {
				//获取题目信息
				ExaminationQuestions examinationQuestions = examinationQuestion.get(i);
				//获取题目类型
				String ixeqType = examinationQuestions.getIxeqType();
				//如果是单选题 则查询选项的人数
				if (ixeqType.equals("O")) {
					//定义选项数组
					String [] arr = {"A","B","C","D"};
					JSONArray jsonArray = new JSONArray();
					//首先查询情况
					for (int j = 0; j < arr.length; j++) {
						JSONObject jsonObject0 = new JSONObject();
						//获取元素
						String option = arr[j];
						jsonObject0.put("option", option);
						JSONArray jsonArray1 =  new JSONArray();
						//获取选择此选项的学生名单
						hashMap.put("ixesId", ixesId);
						hashMap.put("ixeqId", ixeqId);
						hashMap.put("ixscId", ixscId);
						hashMap.put("ixqsAnswer", option);
						List<QuestionScore> questionScoresInfos = smallAppTeacherMapper.getQuestionScoresInfoo(hashMap);
						for (int k = 0; k < questionScoresInfos.size(); k++) {
							JSONObject jsonObject1 = new JSONObject();
							//获取选项的对象
							QuestionScore questionScore = questionScoresInfos.get(k);
							//获取学生信息id
							String ixssId = questionScore.getIxssId();
							//获取学生姓名
							hashMap.put("lineKey", "ixssId");
							hashMap.put("lineValue", ixssId);
							SchoolStudent schoolStudentInfo = smallAppTeacherMapper.getSchoolStudentInfo(hashMap);
							String ixssName = schoolStudentInfo.getIxssName();
							jsonObject1.put("ixssId", ixssId);
							jsonObject1.put("ixssName", ixssName);
							jsonArray1.add(jsonObject1);
						}
						jsonObject0.put("optionArray", jsonArray1);
						jsonArray.add(jsonObject0);
					}
					//选项个数
					int jsonArraySize = jsonArray.size();
					jsonObject.put("questype", "O");
					jsonObject.put("optionArr", jsonArray);
					jsonObject.put("optionNum", jsonArraySize);
				}else if (ixeqType.equals("M")) {
					//如果是多选题 则查询得分的人数
					//获取题目的分数情况
					List<String> list = new LinkedList<>();
					JSONArray jsonArray = new JSONArray();
					hashMap.put("ixesId", ixesId);
					hashMap.put("ixeqId", ixeqId);
					hashMap.put("ixscId", ixscId);
					List<QuestionScore> questionScoresInfod = smallAppTeacherMapper.getQuestionScoresInfod(hashMap);
					for (int j = 0; j < questionScoresInfod.size(); j++) {
						list.add(questionScoresInfod.get(j).getIxqsScore());
					}
					//对分数进行排序
					Collections.sort(list);
					//循环获取分数段
					for (int k = 0; k < list.size(); k++) {
						String score = list.get(k);
						JSONObject jsonObject0 = new JSONObject();
						jsonObject0.put("option", score);
						//获取选择此分数的学生名单
						hashMap.put("ixesId", ixesId);
						hashMap.put("ixeqId", ixeqId);
						hashMap.put("ixscId", ixscId);
						hashMap.put("ixqsScore", score);
						JSONArray jsonArray1 = new JSONArray();
						List<QuestionScore> questionScoresInfom = smallAppTeacherMapper.getQuestionScoresInfom(hashMap);
						for (int m = 0; m < questionScoresInfom.size(); m++) {
							JSONObject jsonObject1 = new JSONObject();
							//获取选项的对象
							QuestionScore questionScore = questionScoresInfom.get(m);
							//获取学生信息id
							String ixssId = questionScore.getIxssId();
							//获取学生姓名
							hashMap.put("lineKey", "ixssId");
							hashMap.put("lineValue", ixssId);
							SchoolStudent schoolStudentInfo = smallAppTeacherMapper.getSchoolStudentInfo(hashMap);
							String ixssName = schoolStudentInfo.getIxssName();
							jsonObject1.put("ixssId", ixssId);
							jsonObject1.put("ixssName", ixssName);
							jsonArray1.add(jsonObject1);
						}
						jsonObject0.put("optionArray", jsonArray1);
						jsonArray.add(jsonObject0);
					}
					//选项个数
					int jsonArraySize = jsonArray.size();
					jsonObject.put("questype", "M");
					jsonObject.put("optionArr", jsonArray);
					jsonObject.put("optionNum", jsonArraySize);
				}else if (ixeqType.equals("S")) {
					//如果是主观题 则查询得分的人数
					//获取题目的区分区间
					JSONArray jsonArray = new JSONArray();
					hashMap.put("ixscId", ixscId);
					hashMap.put("ixeqId", ixeqId);
					List<SubjectiveQuestionsInterval> subjectiveQuestionsIntervals = smallAppTeacherMapper.getSubjectiveQuestionsIntervals(hashMap);
					for (int j = 0; j < subjectiveQuestionsIntervals.size(); j++) {
						JSONObject jsonObject0 = new JSONObject();
						//获取区间对象
						SubjectiveQuestionsInterval subjectiveQuestionsInterval = subjectiveQuestionsIntervals.get(j);
						String iessInterval = subjectiveQuestionsInterval.getIessInterval();
						jsonObject0.put("option", iessInterval);
						//获取上下限
						String[] arr = iessInterval.split("~");
						String ixqsScore0 = arr[0].replace("[", "").replace("(", "");
						String ixqsScore1 = arr[1].replace("]", "").replace(")", "");
						//获取详细的人员信息
						if (j==0) {
							hashMap.put("flag", 0);
						}else {
							hashMap.put("flag", 1);
						}
						hashMap.put("ixqsScore0", ixqsScore0);
						hashMap.put("ixqsScore1", ixqsScore1);
						JSONArray jsonArray1 = new JSONArray();
						List<QuestionScore> questionScoresInfos = smallAppTeacherMapper.getQuestionScoresInfos(hashMap);
						for (int m = 0; m < questionScoresInfos.size(); m++) {
							JSONObject jsonObject1 = new JSONObject();
							//获取选项的对象
							QuestionScore questionScore = questionScoresInfos.get(m);
							//获取学生信息id
							String ixssId = questionScore.getIxssId();
							//获取学生姓名
							hashMap.put("lineKey", "ixssId");
							hashMap.put("lineValue", ixssId);
							SchoolStudent schoolStudentInfo = smallAppTeacherMapper.getSchoolStudentInfo(hashMap);
							String ixssName = schoolStudentInfo.getIxssName();
							jsonObject1.put("ixssId", ixssId);
							jsonObject1.put("ixssName", ixssName);
							jsonArray1.add(jsonObject1);
						}
						jsonObject0.put("optionArray", jsonArray1);
						jsonArray.add(jsonObject0);
					}
					//选项个数
					int jsonArraySize = jsonArray.size();
					jsonObject.put("questype", "S");
					jsonObject.put("optionArr", jsonArray);
					jsonObject.put("optionNum", jsonArraySize);
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return jsonObject;
	}
}
